﻿///<reference path="json2.js" />
///<reference path="jquery-1.9.1-vsdoc.js" />
///<reference path="QQWeiBoLogin.js" />
function DataSync(IsUpload) {
    var LoginUserKey = localStorage.getItem("LoginUserKey");
    if (LoginUserKey == null) {
        alert("请登陆!!!");
        return false;
    }
    if (IsUpload) {
        UpLoadDataToServer();
    } else {
        DownloadDataToClient();
    }
}
function GetLocalStorageItems() {
    var Items = [];
    for (var i = 0, j = localStorage.length; i < j; i++) { 
        var KeyName=localStorage.key(i);
        var item = new LocalStorageItem(KeyName, localStorage.getItem(KeyName));
        Items.push(item);
    }
    return Items;
}
function LocalStorageItem(key, value) {
    this.Key = key;
    this.Value = value;
}
function GetLastModifyDateInServer() {
    var LoginUserKey = localStorage.getItem("LoginUserKey");
    if (LoginUserKey == null) {
        return false;
    }
    $.post("AjaxRequest.ashx", { _type: "GetLastModifyDate", UserKey: LoginUserKey }, function (data) {
        var ServerTicks = parseInt(data.LastModifyTicks, 10);
        var LocalTicks = localStorage.getItem("localStorage_LastModifyDate");
        if (LocalTicks == null) {
            LocalTicks = 0;
        } else {
            LocalTicks = parseInt(LocalTicks, 10);
        }
        if (Ticks > 0) {

        }
    }, "json");
}
function UpLoadDataToServer() {
    var LoginUserKey = localStorage.getItem("LoginUserKey");
    if (LoginUserKey == null) {
        return false;
    }
    var StorageJsonString = JSON.stringify(GetLocalStorageItems());
    $.post("AjaxRequest.ashx", { _type: "UpLoadData", UserKey: LoginUserKey, Data: StorageJsonString }, function (data) {
        if (data.Value == "True") {
            alert("上传成功");
        } else
        { alert("上传失败"); }
    }, "json");
}
function DownloadDataToClient() {
    var LoginUserKey = localStorage.getItem("LoginUserKey");
    if (LoginUserKey == null) {
        return false;
    }
    $.post("AjaxRequest.ashx", { _type: "DownloadData", UserKey: LoginUserKey }, function (data) {
        for (var i = 0, j = data.length; i < j; i++) {
            var item = data[i];
            localStorage.setItem(item.Key, item.Value);
        }
        CreateTypeSelectOption();
        CreateUrlListSelectOption();
        alert("加载成功");
    }, "json");
}